package dao;

import org.apache.ibatis.annotations.*;
import pojo.Yytx;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
/**
 * 用药提醒数据访问接口（完整映射）
 */
public interface YytxMapper {
    // 新增提醒（完整字段映射）
    @Insert("INSERT INTO yytx (" +
            "yh_id, medicine_name, dosage, remind_time, " +
            "frequency, status, create_time) " +
            "VALUES (" +
            "#{yhId}, #{medicineName}, #{dosage}, #{remindTime}, " +
            "#{frequency}, #{status}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "yytxId")
    int add(Yytx yytx);

    // 查询某用户的所有提醒
    @Select("SELECT * FROM yytx WHERE yh_id = #{yhId} ORDER BY remind_time ASC")
    List<Yytx> findByYhId(Integer yhId);

    // 按时间范围查询提醒
    @Select("SELECT * FROM yytx " +
            "WHERE yh_id = #{yhId} " +
            "AND remind_time BETWEEN #{startTime} AND #{endTime} " +
            "ORDER BY remind_time ASC")
    List<Yytx> findByTimeRange(
            @Param("yhId") Integer yhId,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime
    );

    // 更新提醒（完整字段映射）
    @Update("UPDATE yytx SET " +
            "medicine_name = #{medicineName}, " +
            "dosage = #{dosage}, " +
            "remind_time = #{remindTime}, " +
            "frequency = #{frequency}, " +
            "status = #{status} " +
            "WHERE yytx_id = #{yytxId}")
    int update(Yytx yytx);

    // 删除提醒
    @Delete("DELETE FROM yytx WHERE yytx_id = #{yytxId}")
    int deleteById(Integer yytxId);

    // 删除某用户的所有提醒
    @Delete("DELETE FROM yytx WHERE yh_id = #{yhId}")
    int deleteByYhId(Integer yhId);
}